<template>
	<view>
		<uni-nav-bar :statusBar="true" dark title="球队" fixed left-icon="left" @clickLeft="clickLeft">
			<block slot="right">
				<view class="city">
					<view @click="onSave">
						保存
					</view>
				</view>
			</block>
		</uni-nav-bar>
		<view>
			<uni-collapse accordion  >
				<uni-collapse-item :class="teamList.indexOf(item.id) != -1 ? 'active' : ''" :show-arrow="false" :title="item.teamName" v-for="(item,index) in list">
					<block slot="title">
						<view class="contentList" @click="onShowData(item.id)">
							<image v-if="item.teamLogo" :src="imageUrl + item.teamLogo" mode=""></image>
							<image v-else src="@/static/user.jpg"></image>
							<view>
								<view>{{item.teamName}}</view>
							</view>
						</view>
					</block>
				</uni-collapse-item>
			</uni-collapse>
		</view>
		<uni-load-more :status="loadingType"></uni-load-more>
	</view>
</template>

<script>
	import {
		getbasketballTeamList,
		createTeanGroupingPlayTeam
	} from '@/api/basketballTeam/index.js'
	import {imageUrl} from '@/config.js'
	export default {
		data() {
			return {
				list: [],
				pageData: {
					pageSize: 10,
					pageNum: 1
				},
				total: 0,
				loadingType: 'more',
				imageUrl: imageUrl,
				id: '',
				teamList: [],
				activeShow:''
			}
		},
		onLoad(option) {
			this.id = option.id
		},
		methods: {
			clickLeft() {
				uni.navigateBack()
			},
			onShowData(id){
				if (this.teamList.indexOf(id)  == -1) {
					this.teamList.push(id)
				} else {
					this.teamList.splice(this.teamList.indexOf(id), 1)
				}
				var arr = this.teamList.map(item => {
					return this.activeShow = item
				})
			},
			onSave(){
				var arr = this.teamList.map(item => {
					return {
						basketballTeamId: item,
						teamGroupingId:this.id
					}
				})
				createTeanGroupingPlayTeam(arr).then(res => {
					this.$modal.msg(res.msg)
					uni.navigateTo({
						url: '/pages/createGroup/group?id=' + this.id
					})
				})
			},
			getList() {
				let id = uni.getStorageSync('contestId')
				getbasketballTeamList({leagueId:id,...this.pageData}).then(res => {
					this.total = res.total
					this.list.push(...res.rows)
					if (this.list.length == this.total) {
						this.loadingType = 'no-more'
						return;
					}
				})
			}
		},
		async onReachBottom() {
			if (this.list.length == this.total) {
				this.loadingType = 'no-more'
				return;
			}
			this.loadingType = 'loading'
			this.pageData.pageNum += 1
			this.getList()
		},
		onShow() {
			this.pageData = {
				pageNum: 1,
				pageSize: 10
			}
			this.list = []
			console.log(imageUrl);
			this.getList();
		}
	}
</script>

<style scoped lang="scss">
.contentList {
	display: flex;
	padding: 30rpx;
	align-items: center;
	font-weight: 600;
	image {
		width: 100rpx;
		height: 100rpx;
		border-radius: 100%;
		margin-right: 20rpx;
	}
}
.active {
	background: #eee;
}
.contentBtn {
	display: flex;
	align-items: center;
	background-color: #F7F7F7;
	view {
		height: 20px;
		width: 1px;
		background-color: #E2E2E2;
	}
	button {
		width: calc(100% / 2);
		border: none;
		font-size: 28rpx;
		border-radius: 0;
		color: #7F7F7F;
		padding-top: 20rpx;
		padding-bottom: 20rpx;
		&::after{
			border: none;
		}
	}
}
.popupbox {
	background-color: #fff;
	min-height: 800rpx;
	.content {
		padding: 40rpx 20rpx;
	
		.logo {
			display: flex;
			align-items: center;
			padding-bottom: 40rpx;
		}
	}
	.bottomBtn {
		display: flex;
		justify-content: center;
		flex-direction: row;
		background-color: #fff;
		position: absolute;
		width: 100%;
		bottom: 0;
		padding: 40rpx 30rpx;
		padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
		border-top: 1px solid #eee;
		.submit-text {
			display: flex;
			
			font-size: 24rpx;
		}
		.submit {
			background-color: $btn-bg-color;
			color: #fff;
			width: 48%;
			font-size: 34rpx;
			font-weight: 800;
			margin-top: 20rpx;
		}
	}
}
</style>